package org.xiaojinlong.thread;

import java.util.concurrent.TimeUnit;

/**
 * @author Jin Long
 *         2015/10/10
 */
public class Interrupt extends Thread {
    @Override
    public void run() {
        for (int i = 0; i < Integer.MAX_VALUE; i++) {
            System.out.println(i);
            if (isInterrupted()) {
                System.out.println("Interrupted...");
                return;
            }
        }
    }

    public static void main(String[] args) {
        Interrupt i = new Interrupt();
        i.start();
        try {
            TimeUnit.SECONDS.sleep(2);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        i.interrupt();
    }
}
